草庐IT

PHPUnit 和 CodeIgniter

全部标签

Phpunit,如何删除模拟对象?

我有两个不同的测试用例,都对一个方法进行了模拟。有没有办法清理模拟对象?因为测试方法有不同的期望 最佳答案 可能你需要使用Mock::close():...publicfunctiontearDown(){Mockery::close();}... 关于Phpunit,如何删除模拟对象?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/26343864/

php - codeigniter 路由任何或 num 不工作

我有这样的urlhttp://lp.dev/sisters/adab/1但是当我使用(:num)或(:any)获取值1因为路由给我404页面路线如下$route['default_controller']="frontend/home";$route["sisters/adab/(:num)"]="frontend/pages/$1";//Controller:前端文件夹内的pages.phpclassPagesextendsCI_Controller{function__construct(){parent::__construct();$this->name=$this->uri-

php - 使用 codeigniter 设置 cron 作业

我有一个函数要通过cron执行。如果我只是点击urlwww.example.com/TestProjects/codeigniter/controller/function这个函数执行得很好,如果我在cron上设置它不起作用。我尝试将其设置为public_html/TestProjects/codeigniter/controller/function然后通过这样的错误信息public_html/TestProjects/codeigniter/controller/function:Notadirectory谁能帮我在cron上设置这个? 最佳答案

php - 助手没有加载到 Codeigniter 中?

这是我的简单Controller:publicfunction_construct(){parent::_construct();$this->load->helper('url');}publicfunctionview($page="index"){if(!file_exists(APPPATH.'/views/truelove_view/'.$page.'.php')){//Whoops,wedon'thaveapageforthat!show_404();}$this->load->view('truelove_view/templates/header.php');$this

symfony2 中的 phpunit - 未执行任何测试

已解决-请参阅下面的答案我有一个问题。我正在尝试使用phpunit测试一些功能测试。问题是,当我在命令提示符下使用phpunit-capp时,我得到Notestsexecuted!。看来我申请的路径不对。我试图更改我的phpunit.xml.dist中的路径。我改了很多次,但“猜”标准代码似乎是最好的,../src/*/*Bundle/Tests../src/*/Bundle/*Bundle/Tests这些链接似乎不起作用。我还查找了文件“phpunit.xml”,因为它可能会覆盖我的.dist文件。我没有文件。我还检查了symfony文档。我认为这可能是因为我有一个“LocalApp

php - 将 Bootstrap 集成到 codeigniter

我在CI上的$route上有这个$route['(:any)']='main/index/$1';$route['default_controller']='main/index';$route['404_override']='';$route['translate_uri_dashes']=FALSE;我还从startbootstrap下载了一个bootstrap主题,我搬家了css,fonts,images,js进入根目录,应用程序文件夹所在的位置所以问题在于codeigniter将“css”读取为Controller,因此View无法访问css。我也在看有关如何集成它的教程。[

php - codeigniter:如何从指定索引转换数组值?

我有一个这样的数组array(2){[0]=>object(stdClass)#20(4){["id"]=>string(1)"1"["name"]=>string(6)"robert"["height"]=>string(3)"165"["weight"]=>string(2)"81"}[1]=>object(stdClass)#21(4){["id"]=>string(1)"2"["name"]=>string(4)"mike"["height"]=>string(3)"175"["weight"]=>string(2)"69"}}所以,我想更改我的数组值。例如,我想更改["hei

php - 使用 PHPUnit 测试 Guzzle 调用时无法找到包装器

我正在为我正在开发的API编写单元测试。API是在Codeigniter框架中编写的,它使用Guzzle调用另一个API。我正在编写的测试验证API调用是否返回正确的响应。Test.php文件包含以下代码require'/application/libraries/apiWrappers/Breathehr.php';classBreathehrTestextendsPHPUnit_Framework_TestCase{publicfunctiontestCanReturnEmployeeArray(){$breatheHR=newBreathehr();$employees=$bre

php - 如何在 codeigniter 验证中允许空格、逗号、点和字母

在我的View页面中。我有一个用于输入评论的文本框。在我的codeigniter验证中只允许alpha。我需要在评论字段中允许空格、逗号、点、连字符..这个地方在我的验证集中规则如何$this->form_validation->set_rules('e_comment','Comments','required|alpha'); 最佳答案 要进行自定义验证,您需要使用callback功能。//validationrule$this->form_validation->set_rules('comment','Comments','

PHPUnit 无法通过命名空间自动加载找到类

我们有以下简化的文件夹结构:phpunit.xmlautoloading.phpindex.php/models/useruser.php.../settingspreferences.php.../teststest.php这是相关文件的内容:模型/用户/user.phpnamespacemodels\user;classUser{private$preferences;publicfunction__construct(){$this->preferences=new\models\settings\Preferences();}publicfunctiongetPreferenc